<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
    <script src="../../../resources/js-test.js"></script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
    if (window.testRunner) {
        testRunner.dumpAsText();
    }

    window.moveTo(0,0);

    description("This test makes sure that we have similar behavior as other\
    browsers when resizing and moving a window outside of the screen.  This test\
    will fail in some dimensions when run manually because of inconsistencies of\
    when the window can and cannot go behind the doc.");
    
    var result;
    var testName;
    var x;
    var y;

    // resizeTo /////////////////////////
    debug('');
    debug('window.resizeTo Tests');
    debug('');

    x = screen.width*2;
    y = screen.height*2;
    window.resizeTo(x, y);
    debug("Testing - resizeTo: Too Big");
    shouldBeTrue('window.outerWidth == screen.availWidth');

    debug('');

    x = 50;
    y = 50;
    window.resizeTo(x, y);
    debug("Testing - resizeTo: Too Small");
    shouldBeTrue('window.outerWidth == 100');

    debug('');
    x = screen.width/10;
    y = screen.height/10;
    window.moveTo(x, y);
    x = screen.width;
    y = screen.height;
    window.resizeTo(x, y);
    debug("Testing - resizeTo: Full Screen Out of Bounds");
    shouldBeTrue('window.screenY == screen.availTop');
    shouldBeTrue('window.outerHeight == screen.availHeight');
    shouldBeTrue('window.screenX == screen.availLeft');
    shouldBeTrue('window.outerWidth == screen.availWidth');

    debug('');
    x = 100;
    y = 100;
    window.resizeTo(x, y);
    x = screen.width/2;
    y = screen.height/2;
    window.moveTo(x, y);
    x += 10;
    y += 10;
    window.resizeTo(x, y);
    debug("Testing - resizeTo: Not Full Screen Out of Bounds");
    shouldBeTrue('window.outerHeight + window.screenY - screen.availTop == screen.availHeight');
    shouldBeTrue('window.outerWidth + window.screenX - screen.availLeft == screen.availWidth');

    // resizeBy /////////////////////////
    debug('');
    debug('window.resizeBy Tests');
    debug('');

    x = 150;
    y = 150;
    window.resizeTo(x, y);
    x = -100;
    y = -100;
    window.resizeBy(x, y);
    debug("Testing - resizeBy: Too Small");
    shouldBeTrue('window.outerWidth == 100');

    debug('');

    x = screen.width*2;
    y = screen.height*2;
    window.resizeBy(x, y);
    debug("Testing - resizeBy: Too Big");
    shouldBeTrue('window.outerWidth == screen.availWidth');

    window.moveTo(0,0);
    window.resizeTo(screen.width, screen.height);

    // moveTo /////////////////////////
    debug('');
    debug('window.moveTo Tests');
    debug('');

    x = -100;
    y = -100;
    window.moveTo(x, y);
    debug("Testing - moveTo: Top Left");
    shouldBeTrue('window.screenY == screen.availTop');
    shouldBeTrue('window.screenX == screen.availLeft');

    debug('');

    x = 0;
    y = -100;
    window.moveTo(x, y);
    debug("Testing - moveTo: Top");
    shouldBeTrue('window.screenY == screen.availTop');
    shouldBeTrue('window.screenX == screen.availLeft');

    debug('');

    x = 100;
    y = -100;
    window.moveTo(x, y);
    debug("Testing - moveTo: Top Right");
    shouldBeTrue('window.screenY == screen.availTop');
    shouldBeTrue('window.outerWidth == screen.availWidth');

    debug('');

    x = 100;
    y = 0;
    window.moveTo(x, y);
    debug("Testing - moveTo: Right");
    shouldBeTrue('window.screenY == screen.availTop');
    shouldBeTrue('window.outerWidth == screen.availWidth');

    debug('');

    x = 100;
    y = 100;
    window.moveTo(x, y);
    debug("Testing - moveTo: Bottom Right");
    shouldBeTrue('window.outerHeight == screen.availHeight');
    shouldBeTrue('window.outerWidth == screen.availWidth');

    debug('');

    x = 0;
    y = 100;
    window.moveTo(x, y);
    debug("Testing - moveTo: Bottom");
    shouldBeTrue('window.outerHeight == screen.availHeight');
    shouldBeTrue('window.screenX == screen.availLeft');

    debug('');

    x = -100;
    y = 100;
    window.moveTo(x, y);
    debug("Testing - moveTo: Bottom Left");
    shouldBeTrue('window.outerHeight == screen.availHeight');
    shouldBeTrue('window.screenX == screen.availLeft');

    debug('');

    x = -100;
    y = 0;
    window.moveTo(x, y);
    debug("Testing - moveTo: Left");
    shouldBeTrue('window.screenY == screen.availTop');
    shouldBeTrue('window.screenX == screen.availLeft');

    window.moveTo(0,0);
    window.resizeTo(screen.width, screen.height);

    // moveBy /////////////////////////
    debug('');
    debug('window.moveBy Tests');
    debug('');

    x = 100;
    y = 100;
    window.resizeTo(x, y);

    x = 200;
    y = 200;
    window.moveTo(x, y);

    var previousScreenX = window.screenX;
    var previousScreenY = window.screenY;

    x = 0;
    y = 0;
    window.moveBy(x, y);
    debug("Testing - moveBy: Zero Zero");
    shouldBeTrue('window.screenX == previousScreenX');
    shouldBeTrue('window.screenY == previousScreenY');

    debug('');

    previousScreenX = window.screenX;
    previousScreenY = window.screenY;
    x = 1;
    y = 0;
    window.moveBy(x, y);
    debug("Testing - moveBy: One Zero");
    shouldBeTrue('window.screenX == previousScreenX + 1');
    shouldBeTrue('window.screenY == previousScreenY');

    debug('');

    previousScreenX = window.screenX;
    previousScreenY = window.screenY;
    x = 0;
    y = 1;
    window.moveBy(x, y);
    debug("Testing - moveBy: Zero One");
    shouldBeTrue('window.screenX == previousScreenX');
    shouldBeTrue('window.screenY == previousScreenY + 1');

    debug('');

    window.moveTo(0,0);
    window.resizeTo(screen.width, screen.height);

    x = -100;
    y = -100;
    window.moveBy(x, y);
    debug("Testing - moveBy: Top Left");
    shouldBeTrue('window.screenY == screen.availTop');
    shouldBeTrue('window.screenX == screen.availLeft');

    debug('');

    x = 0;
    y = -100;
    window.moveBy(x, y);
    debug("Testing - moveBy: Top");
    shouldBeTrue('window.screenY == screen.availTop');
    shouldBeTrue('window.screenX == screen.availLeft');

    debug('');

    x = 100;
    y = -100;
    window.moveBy(x, y);
    debug("Testing - moveBy: Top Right");
    shouldBeTrue('window.screenY == screen.availTop');
    shouldBeTrue('window.outerWidth == screen.availWidth');

    debug('');

    x = 100;
    y = 0;
    window.moveBy(x, y);
    debug("Testing - moveBy: Right");
    shouldBeTrue('window.screenY == screen.availTop');
    shouldBeTrue('window.outerWidth == screen.availWidth');

    debug('');

    x = 100;
    y = 100;
    window.moveBy(x, y);
    debug("Testing - moveBy: Bottom Right");
    shouldBeTrue('window.outerHeight == screen.availHeight');
    shouldBeTrue('window.outerWidth == screen.availWidth');

    debug('');

    x = 0;
    y = 100;
    window.moveBy(x, y);
    debug("Testing - moveBy: Bottom");
    shouldBeTrue('window.outerHeight == screen.availHeight');

    debug('');

    x = -1000;
    y = 100;
    window.moveBy(x, y);
    debug("Testing - moveBy: Bottom Left");
    shouldBeTrue('window.outerHeight == screen.availHeight');
    shouldBeTrue('window.screenX == screen.availLeft');

    debug('');

    x = -100;
    y = 0;
    window.moveBy(x, y);
    debug("Testing - moveBy: Left");
    shouldBeTrue('window.screenX == screen.availLeft');

    debug('');

    window.moveTo(0,0);
    window.resizeTo(800,600);
</script>
</body>
</html>
